package com.kaishengit.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.pojo.Goal;
import com.kaishengit.pojo.Task;
import com.kaishengit.pojo.User;
import com.kaishengit.util.CreateTime;
import com.kaishengit.util.MyUUID;

@Service
@Transactional
public class TaskService extends BaseService{

	public List<Task> finAllTask(Goal goal){
		List<Task> taskList=getTaskDao().findAllTask(goal);
		return taskList;
	}
	
	public void save(Task task, User user, Goal goal) {
		task.setId(MyUUID.createUUID().toString());
		task.setCreatetime(CreateTime.createTime());
		task.setUser(user);
		task.setGoal(goal);
		getTaskDao().save(task);
	}
	
	public void update(Task task, String id, User user) {
		Task tas=getTaskDao().findById(id);
		
		tas.setBegintime(task.getBegintime());
		tas.setContent(task.getContent());
		tas.setEndtime(task.getEndtime());
		tas.setLevel(task.getLevel());
		tas.setName(task.getName());
		tas.setRate(task.getRate());
		tas.setState(task.getState());
		tas.setUser(user);
		getTaskDao().update(tas);
	}
	
	public List<Task> findTaskByUser(User user){
		return getTaskDao().findTaskByUser(user);
	}

	public Task findById(String id) {
		
		return getTaskDao().findById(id);
	}
}
